<?php
namespace App\Admin\Models;
use Common\BaseModel;
class ArticleFaquan extends BaseModel
{
    protected $res;
    public $key;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_article_faquan');
    }

    /**
     * 获取具体的内容
     * @param int $cid 栏目id
     * @param int $cateid 分类id
     * @param int $is_recommend 是否首页推荐
     * @return mixed
     */
    public function find_list($params){
        $conditions='';
        if(isset($params['cid']) || !empty($params['cid'])){
            if($conditions){
                $conditions="AND cateid={$params['cid']}";
            }else{
                $conditions="cateid={$params['cid']}";
            }
        }
        if(isset($params['keywords']) || !empty($params['keywords'])){
            if($conditions){
                $conditions="AND itemid like '%{$params['keywords']}%'";
            }else{
                $conditions="itemid like '%{$params['keywords']}%'";
            }
        }

        $order="id DESC";
        $user_list = $this::find(
            array(
                $conditions,
                "order" => $order,
            )
        );
        return $user_list;
    }


    /**
     * 根据id获取营销分类的名称
     */
    public function find_first_by_Id($id){
        if(empty($id)){
            return '';
        }
        $cate_info = $this->findFirstById($id);
        if($cate_info){
            return $cate_info->toarray();
        }else{
            return [];
        }

    }





    /**
     * 根据商品id获取产品
     */
    public function find_goods_itemsid($itemid){
        if(empty($itemid)){
            return '';
        }
        $condition = "itemid='{$itemid}'";
        $count_items = $this->count(
            array(
                $condition,
            )
        );
        return $count_items;
    }


    /**
     * 获取具体的内容
     * @param int $cid 栏目id
     * @param int $cateid 分类id
     * @param int $is_recommend 是否首页推荐
     * @return mixed
     */
    public function find_count($cid){
        $conditions="cateid={$cid}";
        $order="id DESC";
        $user_count = $this::count(
            array(
                $conditions,
                "order" => $order,
                "columns"=>"id",
                "limit"=>1
            )
        );
        return $user_count;
    }


    public function save_params($params){
        return $this::save($params);
    }




}
